#include <kernel/io.hpp>
#include <kernel/arch/i386/interrupts/pic.hpp>

namespace pic
{

void initializePic()
{
	remap();
}

void sendEndOfInterrupt(uint32_t interruptNumber)
{
	if(interruptNumber >= slaveOffset)
		outb(slaveCommand, Command::EndOfInterrupt);

	outb(masterCommand, Command::EndOfInterrupt);
}

void remap()
{
	outb(masterCommand, Command::Init | Command::RequireIcw4);
	outb(slaveCommand, Command::Init | Command::RequireIcw4);
	outb(masterData, masterOffset);
	outb(slaveData, slaveOffset);

	outb(masterData, MasterInterrupMask::Cascade);
	outb(slaveData, SlaveInterruptMask::CascadeIdentity);
	outb(masterData, InitCommandWord4::Mode8086);
	outb(slaveData, InitCommandWord4::Mode8086);
   outb(masterData, ~MasterInterrupMask::Keyboard);
   outb(slaveData, ~UINT8_C(0));
}

}
